package com.cupdata.marathon.config;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.redisson.api.RedissonClient;
import org.redisson.spring.data.connection.RedissonConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;

@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "PT20S")
public class ShedlockRedisConfig {

    @Resource(name = "redissonCluster")
    private RedissonClient redissonCluster;

    @Bean
    public LockProvider lockProvider() {
        return new RedisLockProvider(new RedissonConnectionFactory(redissonCluster));
    }
}
